<template>
  <div>
    <el-form :model="apply_form" class="search_prod" label-width="120px">
      <el-form-item label="用户名">
        <el-col :span="4">
          <el-col :span="16" class="search_input_width">
            <el-input size="small" clearable placeholder="用户名" v-model="apply_form.username"></el-input>
          </el-col>
        </el-col>
        <el-col class="tr col_label" :span="3">昵称&nbsp;&nbsp;&nbsp;</el-col>
        <el-col :span="4">
          <el-col :span="16" class="search_input_width">
            <el-input size="small" clearable placeholder="昵称" v-model="apply_form.nickname"></el-input>
          </el-col>
        </el-col>
        <el-col class="tr col_label" :span="3">是否支付&nbsp;&nbsp;&nbsp;</el-col>
        <el-col :span="4">
          <el-col :span="16" class="search_input_width">
            <el-select v-model="apply_form.is_pay" clearable size="small" placeholder="审核状态">
              <el-option
                v-for="item in showoption"
                size="small"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-col>
        </el-col>
      </el-form-item>

      <el-form-item label="时间区间">
        <el-col :span="4">
          <el-col :span="16" class="search_input_width">
            <el-date-picker
              style="width:100%"
              v-model="createTime"
              type="daterange"
              size="small"
              align="right"
              unlink-panels
              value-format="timestamp"
              range-separator="-"
              clearable
              start-placeholder="浏览时间起"
              end-placeholder="浏览时间止"
              :picker-options="pickerOptions2"
            ></el-date-picker>
          </el-col>
        </el-col>
      </el-form-item>
      <el-form-item>
        <el-row class="tl">
          <el-col :span="24">
            <el-button size="mini" type="primary" @click="apply_search_btn">查询</el-button>
            <el-button size="mini" type="primary" @click="del_search_btn">一键清除</el-button>
          </el-col>
        </el-row>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
export default {
  name: "countsearch",
  data() {
    return {
      pickerOptions2: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        },
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            }
          }
        ]
      },
      createTime: [],
      showoption: [
        { label: "未支付", value: 0 },
        { label: "支付成功", value: 1 }
      ],
      apply_form: {
        username: "",
        nickname: "",
        is_pay: "",
        created_time_begin: "",
        created_time_end: ""
      }
    };
  },
  components: {},
  methods: {
    del_search_btn() {
      this.apply_form = {
        username: "",
        nickname: "",
        is_pay: "",
        created_time_begin: "",
        created_time_end: ""
      };
      this.createTime = [];
      this.$emit("send_search", this.apply_form);
    },
    apply_search_btn() {
      this.$emit("send_search", this.apply_form);
    }
  },
  watch: {
    createTime(val) {
      if (val != null) {
        this.apply_form.created_time_begin = this.$fnc.phptime(val[0]);
        this.apply_form.created_time_end = this.$fnc.phptime(val[1]);
      } else {
        this.apply_form.created_time_begin = "";
        this.apply_form.created_time_end = "";
      }
    }
  }
};
</script>
<style scoped>
</style>
